package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.net.liveService
import com.polaris.live.net.userService
import com.polaris.live.resp.back_resp.PartyGameResp
import com.polaris.live.resp.back_resp.PartyRoomResp
import com.polaris.live.resp.back_resp.PartyThemeResp
import com.polaris.live.resp.back_resp.UserCoverResp
import com.polaris.live.resp.go_resp.ChangeRoomNameRequest
import com.polaris.live.resp.go_resp.SubmitRoomCoverBean
import com.polaris.live.resp.go_resp.UserLoadRoomCoverBean

/**
 * SetPartyImageViewModel
 *
 * @author Created by 半仙 on 2024/3/1/001 11:53
 */
class SetPartyImageViewModel : BaseViewModel() {

    /**
     * 获取房间封面照片
     */
    val mUserCoverLiveData = MutableLiveData<ResultState<UserCoverResp>>()
    fun getUserCover(coverType: Int) {
        requestLoading({ userService.getRoomCover(coverType) }, mUserCoverLiveData, waitTime = 0)
    }

    /**
     * 上传房间封面照
     */
    val mUploadCoverLiveData = MutableLiveData<ResultState<UserCoverResp>>()
    fun uploadCover(coverType: Int, url: String) {
        request(
            { userService.uploadRoomCover(UserLoadRoomCoverBean(url, coverType)) },
            mUploadCoverLiveData
        )
    }

    /**
     * 提交房间封面照
     */
    val mSubmitCoverLiveData = MutableLiveData<ResultState<UserCoverResp>>()
    fun submitCover(coverType: Int) {
        request(
            { userService.submitRoomCover(SubmitRoomCoverBean(coverType)) },
            mSubmitCoverLiveData
        )
    }

    /**
     * 获取派对游戏
     */
    val mPartyGameLiveData = MutableLiveData<ResultState<List<PartyGameResp>>>()
    fun getPartyGame() {
        requestLoading({ liveService.getPartyGame() }, mPartyGameLiveData, waitTime = 0)
    }

    /**
     * 获取派对主题
     */
    val mPartyThemeLiveData = MutableLiveData<ResultState<MutableList<PartyThemeResp>>>()
    fun requestPartyTheme() {
        request({ liveService.getPartyTheme() }, mPartyThemeLiveData)
    }

    /**
     * 获取派对房间
     */
    val mPartyRoomLiveData = MutableLiveData<ResultState<PartyRoomResp>>()
    fun getPartyRoom() {
        request({ liveService.getPartyRoom() }, mPartyRoomLiveData)
    }

    /**
     * 修改/保存房间名称
     */
    val mChangeNameLiveData = MutableLiveData<ResultState<Any>>()
    fun changeRoomName(name: String) {
        request({ liveService.changeRoomName(ChangeRoomNameRequest(name)) }, mChangeNameLiveData)
    }
}